package Test10;

import sun.reflect.generics.tree.Tree;

import java.util.Scanner;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-11-06
 * Time: 20:16
 */
 class TreeNode {
    String val;
    TreeNode left;
    TreeNode right;
    public TreeNode(String str) {
        String val = str;
    }


    // 前序遍历   根 -> 左 -> 右
    void preOrder(TreeNode root) {
        if( root == null) {
            return;
        }
        System.out.print(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }

    // 中序遍历   左 -> 根 -> 右
    void inOrder(TreeNode root) {
        if( root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print( root.val + " ");
        inOrder(root.right);
    }

}


public class Test {
   public static TreeNode findVaule(TreeNode root , String val) {
        if( root == null) return null;
        if(root.val.equals(val)) {
            return root;
        }
        //递归查找左子树有无要查找的值,有返回这个节点
        TreeNode ret = findVaule(root.left,val);
        if( ret != null) {
            return ret;
        }
        //递归查找左子树有无要查找的值,有返回这个节点
        ret = findVaule(root.right,val);
        if( ret !=null) {
            return ret;
        }
        //走到这说明左右子树都没有,返回null
        return null;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeNode root = new TreeNode("/");
        int n = sc.nextInt();
        for(int i = 1; i<=n ; i++) {
            String s = sc.next();
            if(findVaule(root,s) == null) {
                TreeNode child = new TreeNode(s);
                if( root.left == null) {
                    root.left = child;
                } else {
                    root.right = child;
                }

            }
        }



    }
}
